package cn.stylefeng.guns.modular.course.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.course.entity.CourseVideo;

import cn.stylefeng.guns.modular.course.service.CourseVideoService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 控制器
 *
 * @author typ
 * @Date 2021-04-24 22:58:06
 */
@Controller
@RequestMapping("/courseVideo")
public class CourseVideoController extends BaseController {

    private String PREFIX = "/courseVideo";

    @Autowired
    private CourseVideoService courseVideoService;

    /**
     * 跳转到主页面
     *
     * @author typ
     * @Date 2021-04-24
     */
    @RequestMapping("")
    public String index(Integer courseId) {
        return PREFIX + "/courseVideo.html";
    }

    /**
     * 新增页面
     *
     * @author typ
     * @Date 2021-04-24
     */
    @RequestMapping("/add")
    public String add(Model model,Integer courseId) {
        System.out.println("courseId========="+courseId);
        model.addAttribute("courseId",courseId);
        return PREFIX + "/courseVideo_add.html";
    }

    /**
     * 编辑页面
     *
     * @author typ
     * @Date 2021-04-24
     */
    @RequestMapping("/edit")
    public String edit(Integer id,Integer courseId) {
        System.out.println("courseId1111========="+courseId);
        return PREFIX + "/courseVideo_edit.html";
    }

    /**
     * 新增接口
     *
     * @author typ
     * @Date 2021-04-24
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(CourseVideo courseVideoParam) {
        this.courseVideoService.add(courseVideoParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author typ
     * @Date 2021-04-24
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(CourseVideo courseVideoParam) {
        this.courseVideoService.update(courseVideoParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author typ
     * @Date 2021-04-24
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(CourseVideo courseVideoParam) {
        this.courseVideoService.delete(courseVideoParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author typ
     * @Date 2021-04-24
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(CourseVideo courseVideoParam) {
        CourseVideo detail = this.courseVideoService.getById(courseVideoParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author typ
     * @Date 2021-04-24
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(CourseVideo courseVideoParam) {
        return this.courseVideoService.findPageBySpec(courseVideoParam);
    }

}


